package com.example.springboot.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * @desc
 * @Author wangsh
 * @date 2018/4/13 22:53
 */

@Aspect
@Component
public class TestAspect {

	/**
	 * 在访问FastJsonController类中的方法之前，调用该方法
	 * @param pjp
	 * @return
	 * @throws Throwable
	 */
	@Around("execution(* com.example.springboot.demo.conroller.FastJsonController..*(..))")
	public Object method(ProceedingJoinPoint pjp) throws Throwable {

		System.out.println("=====Aspect处理=======");
		Object[] args = pjp.getArgs();
		for (Object arg : args) {
			System.out.println("参数为:" + arg);
		}

		long start = System.currentTimeMillis();

		Object object = pjp.proceed();

		System.out.println("Aspect 耗时:" + (System.currentTimeMillis() - start));

		return object;
	}
}
